package cn.gcyl.module.biz.controller.admin.conferenceinvoiceinformation;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.gcyl.framework.common.pojo.PageParam;
import cn.gcyl.framework.common.pojo.PageResult;
import cn.gcyl.framework.common.pojo.CommonResult;
import cn.gcyl.framework.common.util.object.BeanUtils;
import static cn.gcyl.framework.common.pojo.CommonResult.success;

import cn.gcyl.framework.excel.core.util.ExcelUtils;

import cn.gcyl.framework.apilog.core.annotation.ApiAccessLog;
import static cn.gcyl.framework.apilog.core.enums.OperateTypeEnum.*;

import cn.gcyl.module.biz.controller.admin.conferenceinvoiceinformation.vo.*;
import cn.gcyl.module.biz.dal.dataobject.conferenceinvoiceinformation.ConferenceInvoiceInformationDO;
import cn.gcyl.module.biz.service.conferenceinvoiceinformation.ConferenceInvoiceInformationService;

@Tag(name = "管理后台 - 会议报名发票信息")
@RestController
@RequestMapping("/biz/conference-invoice-information")
@Validated
public class ConferenceInvoiceInformationController {

    @Resource
    private ConferenceInvoiceInformationService conferenceInvoiceInformationService;

    @PostMapping("/create")
    @Operation(summary = "创建会议报名发票信息")
    @PreAuthorize("@ss.hasPermission('biz:conference-invoice-information:create')")
    public CommonResult<Long> createConferenceInvoiceInformation(@Valid @RequestBody ConferenceInvoiceInformationSaveReqVO createReqVO) {
        return success(conferenceInvoiceInformationService.createConferenceInvoiceInformation(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新会议报名发票信息")
    @PreAuthorize("@ss.hasPermission('biz:conference-invoice-information:update')")
    public CommonResult<Boolean> updateConferenceInvoiceInformation(@Valid @RequestBody ConferenceInvoiceInformationSaveReqVO updateReqVO) {
        conferenceInvoiceInformationService.updateConferenceInvoiceInformation(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除会议报名发票信息")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('biz:conference-invoice-information:delete')")
    public CommonResult<Boolean> deleteConferenceInvoiceInformation(@RequestParam("id") Long id) {
        conferenceInvoiceInformationService.deleteConferenceInvoiceInformation(id);
        return success(true);
    }

    @DeleteMapping("/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除会议报名发票信息")
                @PreAuthorize("@ss.hasPermission('biz:conference-invoice-information:delete')")
    public CommonResult<Boolean> deleteConferenceInvoiceInformationList(@RequestParam("ids") List<Long> ids) {
        conferenceInvoiceInformationService.deleteConferenceInvoiceInformationListByIds(ids);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得会议报名发票信息")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('biz:conference-invoice-information:query')")
    public CommonResult<ConferenceInvoiceInformationRespVO> getConferenceInvoiceInformation(@RequestParam("id") Long id) {
        ConferenceInvoiceInformationDO conferenceInvoiceInformation = conferenceInvoiceInformationService.getConferenceInvoiceInformation(id);
        return success(BeanUtils.toBean(conferenceInvoiceInformation, ConferenceInvoiceInformationRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得会议报名发票信息分页")
    @PreAuthorize("@ss.hasPermission('biz:conference-invoice-information:query')")
    public CommonResult<PageResult<ConferenceInvoiceInformationRespVO>> getConferenceInvoiceInformationPage(@Valid ConferenceInvoiceInformationPageReqVO pageReqVO) {
        PageResult<ConferenceInvoiceInformationDO> pageResult = conferenceInvoiceInformationService.getConferenceInvoiceInformationPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, ConferenceInvoiceInformationRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出会议报名发票信息 Excel")
    @PreAuthorize("@ss.hasPermission('biz:conference-invoice-information:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportConferenceInvoiceInformationExcel(@Valid ConferenceInvoiceInformationPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<ConferenceInvoiceInformationDO> list = conferenceInvoiceInformationService.getConferenceInvoiceInformationPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "会议报名发票信息.xls", "数据", ConferenceInvoiceInformationRespVO.class,
                        BeanUtils.toBean(list, ConferenceInvoiceInformationRespVO.class));
    }

}